package team.xyg.cdtu2.controller;

import com.mongodb.internal.VisibleForTesting;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.mapping.TextScore;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.Mapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import team.xyg.cdtu2.dto.PlatMapData;
import team.xyg.cdtu2.service.PlatformSalesService;
import team.xyg.cdtu2.service.VisitService;

import java.util.List;
import java.util.Map;

/**
 * @Author liuyufeng
 * @Date 2022/6/28 0028 14:39
 * @Version 1.0
 */
//@RestController
@Controller
public class IndexController {

    @Autowired
    private PlatformSalesController platformSalesController;
    @Autowired
    private PlatformSalesService platformSalesService;
    @Autowired
    private VisitService visitService;


    @RequestMapping("index")
    public String toIndex(Model model) {
        //加载排行前四的电商平台名称以及销售额
        List<PlatMapData> list = platformSalesController.queryTop(4);

        Integer count_sales = platformSalesService.sumMoney();
        Integer count_ip = visitService.countIp();
        model.addAttribute("count_ip",count_ip);
        model.addAttribute("count_sales",count_sales);
        model.addAttribute("data", list);
        model.addAttribute("code", 200);
        model.addAttribute("msg", "success");
        return "index";
    }


}
